import type { PageResult, PageParams } from '@/types/global'
import type { GuessPlayer } from '@/types/home'
// import type { Player } from '@/types/global'
import { http } from '@/utils/http'

// src/services/home.ts
/**
 * 猜你喜欢-小程序
 */
export const getHomeGoodsGuessLikeAPI = (data?: PageParams) => {
  return http<PageResult<GuessPlayer>>({
    method: 'GET',
    url: '/home/goods/guessLike',
    data,
  })
}

type Data<T> = {
  code: string
  msg: string
  result: T
}

/**
 * 获取推荐玩家列表
 * @param data 请求参数
 */
export const getRecommendPlayersAPI = (data?: PageParams) => {
  // 创建静态数据
  const staticPlayers: GuessPlayer[] = [
    {
      id: 1,
      nickname: '甜心小姐姐',
      avatar: 'https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/uploads/slider_3.jpg',
      introduction: '温柔可爱的声音，陪你上分陪你聊天~擅长辅助位置，保护ADC',
      rating: 4.9,
      serviceCount: 1256,
      tags: ['王者荣耀', '辅助', '温柔声线'],
      price: 30,
    },
    {
      id: 2,
      nickname: '峡谷之巅',
      avatar: 'https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/uploads/slider_2.jpg',
      introduction: '王者段位打野选手，带你快速上分，技术过硬不坑队友',
      rating: 4.8,
      serviceCount: 2341,
      tags: ['王者荣耀', '打野', '上分'],
      price: 50,
    },
    {
      id: 3,
      nickname: '电竞少女',
      avatar: 'https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/uploads/slider_3.jpg',
      introduction: '英雄联盟钻石选手，擅长中单位置，教学式陪玩',
      rating: 4.7,
      serviceCount: 987,
      tags: ['英雄联盟', '中单', '教学'],
      price: 40,
    },
    {
      id: 4,
      nickname: '超级奶妈',
      avatar: 'https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/uploads/slider_1.jpg',
      introduction: '专业辅助玩家，保护意识强，让你安心输出无忧',
      rating: 4.6,
      serviceCount: 1543,
      tags: ['王者荣耀', '英雄联盟', '辅助'],
      price: 35,
    },
    {
      id: 5,
      nickname: '狙击之王',
      avatar: 'https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/uploads/slider_2.jpg',
      introduction: 'CS:GO职业选手退役，教你成为狙击大师',
      rating: 5.0,
      serviceCount: 756,
      tags: ['CS:GO', '狙击', '教学'],
      price: 80,
    },
  ]

  // 模拟分页参数
  const page = data?.page || 1
  const pageSize = data?.pageSize || 10
  const startIndex = (page - 1) * pageSize
  const endIndex = startIndex + pageSize
  const paginatedPlayers = staticPlayers.slice(startIndex, endIndex)

  // 返回符合PageResult<Player>格式的数据
  return Promise.resolve({
    code: '00000',
    msg: 'success',
    result: {
      items: paginatedPlayers,
      counts: staticPlayers.length,
      page,
      pages: Math.ceil(staticPlayers.length / pageSize),
      pageSize,
    },
  })
}
